package ch.fhnw.qualiscan.application.elements;

import java.text.SimpleDateFormat;
import java.util.Date;

import ch.fhnw.qualiscan.core.db.pojos.BestPractice;
import ch.fhnw.qualiscan.core.helpers.TextHelper;

import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

public class BestPracticeElement extends VerticalLayout {

	private static final long serialVersionUID = -8543750343582578666L;
	
	BestPractice bestPractice;
	TextHelper textHelper;
	
	public BestPracticeElement(BestPractice bestPractice) {
		textHelper = new TextHelper();
		this.bestPractice = bestPractice;
		
		buildLayout();
	}
	
	private void buildLayout() {
		setMargin(false, false, true, false);
		
		SimpleDateFormat sdfToDate = new SimpleDateFormat("dd.MM.yyyy");
		
		Label title = textHelper.h5(bestPractice.getTitle());
		title.setHeight("100%");
		
		Date unformatedDate = bestPractice.getEditdate();
		String dateString = sdfToDate.format(unformatedDate);
		Label date = textHelper.p(dateString);
		date.setWidth("150px");
		date.setHeight("100%");
		
		Label desc = textHelper.p(bestPractice.getBestpractice());

		HorizontalLayout header = new HorizontalLayout();
		header.setWidth("100%");
		header.setSpacing(true);
		header.addComponent(title);
		header.addComponent(date);
		header.setExpandRatio(title, 1.0f);
		header.setStyleName("bp_header");
		
		addComponent(header);
		addComponent(desc);
	}
}
